module.exports = {
  parseCusomArgs: () => {
    // 解析指令参数
    // 解析 --dbgh 参数
    const proxyMap = {
      local: 'http://127.0.0.1:6789',
      h10: 'http://192.168.0.10:8888',
      h20: 'http://192.168.0.102:6060',
      h30: 'http://192.168.0.80:6060'
    }

    let devProxy = ''
    if (process.env.npm_config_argv) {
      const argv = JSON.parse(process.env.npm_config_argv)
      let dbgh = 'local'
      const { original } = argv
      const argMap = {}
      if (original) {
        if (Array.isArray(original)) {
          original.forEach(item => {
            const p = item.indexOf('=')
            if (p > 0) {
              argMap[item.substring(0, p)] = item.substring(p + 1)
            } else {
              argMap[item] = true
            }
          })
          // console.log('original', argMap)
          if (argMap['--dbgh']) {
            dbgh = argMap['--dbgh']
          }
        }
      }
      const proxy = dbgh || process.env.npm_config_dbgh || 'local'
      devProxy = proxyMap[proxy] || proxyMap['local']
    }

    process.env.VUE_APP_DEBU_HOST = devProxy
  }
}
